package twitter;

import java.util.List;
import twitter4j.FilterQuery;
import twitter4j.Status;
import twitter4j.StatusAdapter;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.UserStream;
import twitter4j.UserStreamListener;
import twitter4j.auth.AccessToken;


public final class TwitterMain extends StatusAdapter {
    public static void main(String[] args) throws TwitterException {
        TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
        StatusListener listener = new StatusListener() {
            @Override
            public void onStatus(Status status) {
             
                System.out.println(
                        status.getUser().getScreenName() + ";" + 
                        status.getText()+ ";" +
                        status.getInReplyToScreenName() + ";" +
                        status.getSource() + ";" +
                        status.getCreatedAt() + ";" +
                        status.getGeoLocation() + ";" +
                        status.getId() +";" +
                        status.getInReplyToStatusId() +";" +
                        status.getInReplyToUserId() +";" +
                        status.getPlace() +";" +
                        status.getRetweetCount() +";" +
                        status.getRetweetedStatus() +";" 
                    );
            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
                //System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
            }

            @Override
            public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
                System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
            }

            @Override
            public void onScrubGeo(long userId, long upToStatusId) {
                //System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
            }

            @Override
            public void onException(Exception ex) {
                ex.printStackTrace();
            }
        };
        
        
        AccessToken accessToken = loadAccessToken(1974522);
        
        twitterStream.setOAuthConsumer("aSSO7RW66soDRkDHAphLYA", "nfcGyW3htxMRFmcB2tEVTRqkwRf0E1p3Oeb2DjjGxs");
        twitterStream.setOAuthAccessToken(accessToken);
        twitterStream.addListener(listener);
        FilterQuery f = new FilterQuery();
        f.track(new String[]{"Telefônica"});
        
        twitterStream.filter(f);
        
        
        
        Twitter twitter = new TwitterFactory().getInstance();
        
        twitter.setOAuthConsumer("aSSO7RW66soDRkDHAphLYA", "nfcGyW3htxMRFmcB2tEVTRqkwRf0E1p3Oeb2DjjGxs");
        twitter.setOAuthAccessToken(accessToken);
        
 
        /*
        List<Status> statuses = twitter.getUserTimeline();
        System.out.println("Showing friends timeline.");
        for (Status status : statuses) {
            System.out.println(status.getUser().getName() + ":" +
                               status.getText());
        }*/       
        System.out.println(twitter.getId());
        
        
        
        
    }
    private static AccessToken loadAccessToken(int useId){
        String token = "38703155-Em6Hle8e4ooynIje4Jigi9nXBW3a5wHnRUib6VcHr";
        String tokenSecret = "l8l66KDTnsee30fc7ZyalHkYuJdMjKtp6OmTyqyWGnc";
        return new AccessToken(token, tokenSecret);
  }
}